const Koa = require('koa');
const Router = require('koa-router');
const views = require('koa-views');
const static = require('koa-static');

const app = new Koa();
const router = new Router();

app.use(views(__dirname + "/views"), {
  extension: "html"
});
app.use(static(__dirname + "/static"));

router.get('/', (ctx, next) => {
  ctx.redirect('/index');
})

router.get('/index', (ctx, next) => {
  ctx.body = '新闻页面';
})

router.get('/details', (ctx, next) => {
  ctx.body = '详细页面';
})

router.get('/test', (ctx, next) => {
  ctx.body = {
    name: '张三',
    age: 20
  };
})

router.get('/page', async (ctx, next) => {
  await ctx.render('index.html');
})

app.use(router.routes());

app.listen(8888);